const { translateTower, translateBloon, translateAreaType } = require('../display/general');

const bloonProperties = ['lead', 'black', 'white', 'purple', 'frozen']

const parseProperties = (properties, translate = false) => {
    let parsed = [];
    for (let i = 0; i < bloonProperties.length; i++) {
        if ((1 << i) & properties) {
            parsed.push(translate ? translateBloon(bloonProperties[i]) : bloonProperties[i]);
        }
    }
    return parsed.join('/');
}

const towerCategory = ["primary", "military", "magic", "support", "hero", "power"]

const parseCategory = (category) => {
    if (category === 0) return 'none'
    let parsed = []
    for (let i = 0; i < towerCategory.length; i++) {
        if ((1 << i) & category) {
            parsed.push(translateTower(towerCategory[i]))
        }
    }
    return parsed.join('/')
}

const parseAreaType = (type, translate = false) => {
    let key = ''
    switch (type) {
        case 1:
            key = 'water'
            break
        case 2:
            key = 'land'
            break
        default:
            throw new Error(`unknown area type: ${type}`)
    }
    return translate ? translateAreaType(key) : key
}

module.exports = {
    parseProperties,
    parseCategory,
    parseAreaType
};